<!--
 * @Description: 分账账户管理
 * @Author: DXV-RGWU-TUFH-RFCY-IEGMYY
 * @Date: 2023-08-11 16:13:59
 * @LastEditTime: 2023-08-22 17:33:05
 * @LastEditors: DXV-RGWU-TUFH-RFCY-IEGMYY
-->

<template>
  <div class="lb-adapay-list">
    <top-nav />
    <div class="page-main">
      <el-row class="page-top-operate">
        <lb-button
          type="primary"
          icon="el-icon-plus"
          @click="$router.push(`/adapay/edit`)"
          v-hasPermi="`${$route.name}-add`"
          >{{ $t('menu.AdapayListAdd') }}</lb-button
        >
      </el-row>
      <el-row class="page-search-form">
        <el-form
          @submit.native.prevent
          :inline="true"
          :model="searchForm"
          ref="searchForm"
        >
          <el-form-item label="输入查询" prop="name">
            <el-input
              v-model="searchForm.name"
              placeholder="请输入卡号或户名"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <lb-button
              size="medium"
              type="primary"
              icon="el-icon-search"
              style="margin-right: 5px"
              @click="getTableDataList(1)"
              >{{ $t('action.search') }}</lb-button
            >
            <lb-button
              size="medium"
              icon="el-icon-refresh-left"
              style="margin-right: 5px"
              @click="resetForm('searchForm')"
              >{{ $t('action.reset') }}</lb-button
            >
          </el-form-item>
        </el-form>
      </el-row>
      <el-table
        v-loading="loading"
        :data="tableData"
        :header-cell-style="{ background: '#f5f7fa', color: '#606266' }"
        style="width: 100%"
      >
        <el-table-column prop="id" label="ID" fixed></el-table-column>
        <el-table-column prop="member_id" label="账户ID" min-width="150" fixed>
        </el-table-column>
        <el-table-column prop="nickName" label="关联用户" min-width="120" fixed>
        </el-table-column>
        <el-table-column
          prop="title"
          label="结算账户类型"
          min-width="120"
          fixed
        >
          <template slot-scope="scope">
            <el-tag :type="scope.row.is_company === 1 ? 'primary' : 'danger'">
              {{ typeText[scope.row.is_company] }}</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column
          prop="card_id"
          label="结算账户银行卡号"
          min-width="150"
        >
        </el-table-column>
        <el-table-column prop="bank_name" label="开户银行名称" min-width="150">
        </el-table-column>
        <el-table-column prop="card_name" label="银行卡户名" min-width="150">
        </el-table-column>
        <el-table-column prop="tel_no" label="手机号" min-width="120">
        </el-table-column>
        <el-table-column prop="status" label="状态">
          <template slot-scope="scope">
            <span :class="[colorType[scope.row.status]]">
              {{ statusType[scope.row.status] }}
            </span>
            <el-popover
              placement="top-start"
              width="400"
              trigger="hover"
              v-if="scope.row.status === 2 && scope.row.failure_reason"
            >
              <div class="f-caption c-title" slot>
                <div class="c-caption pb-sm">拒绝原因：</div>
                <div v-html="scope.row.failure_reason"></div>
              </div>
              <span
                class="iconfont iconwentifankui1 c-warning"
                slot="reference"
              ></span>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column prop="create_time" label="创建时间" min-width="120">
          <template slot-scope="scope">
            <p>{{ scope.row.create_time | handleTime(1) }}</p>
            <p>{{ scope.row.create_time | handleTime(2) }}</p>
          </template>
        </el-table-column>
        <el-table-column label="操作" min-width="160">
          <template slot-scope="scope">
            <div class="table-operate" v-if="scope.row.status !== 0">
              <lb-button
                size="mini"
                plain
                type="primary"
                @click="$router.push(`/adapay/edit?id=${scope.row.id}`)"
                v-hasPermi="`${$route.name}-edit`"
                >{{ $t('action.edit') }}</lb-button
              >
              <lb-button
                size="mini"
                plain
                type="danger"
                @click="confirmDel(scope.row.id)"
                v-hasPermi="`${$route.name}-delete`"
                >{{ $t('action.delete') }}</lb-button
              >
            </div>
          </template>
        </el-table-column>
      </el-table>
      <lb-page
        :batch="false"
        :page="searchForm.page"
        :pageSize="searchForm.limit"
        :total="total"
        @handleSizeChange="handleSizeChange"
        @handleCurrentChange="handleCurrentChange"
      >
      </lb-page>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import moment from 'moment'
export default {
  data () {
    return {
      typeText: { 1: '个体户/企业', 2: '个人' },
      statusType: { 0: '审核中', 1: '审核通过', 2: '审核失败' },
      colorType: { 0: 'c-link', 1: 'c-success', 2: 'c-warning' },
      loading: false,
      searchForm: {
        page: 1,
        limit: 10,
        name: ''
      },
      tableData: [],
      total: 0,
      count: {}
    }
  },
  activated () {
    this.getTableDataList(1)
  },
  computed: {
    ...mapState({
      routesItem: state => state.routes
    })
  },
  methods: {
    resetForm (form) {
      this.$refs[form].resetFields()
      this.getTableDataList(1)
    },
    handleSizeChange (val) {
      this.searchForm.limit = val
      this.handleCurrentChange(1)
    },
    handleCurrentChange (val) {
      this.searchForm.page = val
      this.getTableDataList()
    },
    async toChange (index) {
      this.searchForm.status = index
      this.getTableDataList(1)
    },
    async getTableDataList (flag) {
      if (flag) this.searchForm.page = 1
      this.loading = true
      let { code, data } = await this.$api.adapay.memberList(this.searchForm)
      this.loading = false
      if (code !== 200) return
      this.tableData = data.data
      this.total = data.total
    },
    confirmDel (id) {
      this.$confirm(this.$t('tips.confirmDelete'), this.$t('tips.reminder'), {
        confirmButtonText: this.$t('action.comfirm'),
        cancelButtonText: this.$t('action.cancel'),
        type: 'warning'
      }).then(() => {
        this.updateItem(id, -1)
      }).catch(() => { })
    },
    async updateItem (id, status) {
      this.$api.adapay.memberStatusUpdate({ id, status }).then((res) => {
        if (res.code === 200) {
          this.$message.success(
            this.$t(status === -1 ? 'tips.successDel' : 'tips.successOper')
          )
          if (status === -1) {
            this.searchForm.page = this.searchForm.page < Math.ceil((this.total - 1) / this.searchForm.limit) ? this.searchForm.page : Math.ceil((this.total - 1) / this.searchForm.limit)
            this.getTableDataList()
          }
        } else {
          if (status === -1) return
          this.getTableDataList()
        }
      })
    }
  },
  filters: {
    handleTime (val, type) {
      let time = type === 1 ? moment(val * 1000).format('YYYY-MM-DD') : type === 2 ? moment(val * 1000).format('HH:mm:ss') : moment(val * 1000).format('YYYY-MM-DD HH:mm:ss')
      return time
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
